#!/bin/bash
# DIM维表数据量少，可直接全部覆盖，同全量过程

# 需求：能够手动传入参数指定采集的日期。  如果不传入参数要求能够自动的识别前一天的日期
if [ $# -eq 0 ]
then
    DATESTR=`date -d "-1 day" +%Y-%m-%d`
else
    DATESTR=$1
fi

SQOOP_HOME=/usr/bin/sqoop

# 一、将MySQL数据导入DIM层
# 1.1 导入数据到customer客户表中
${SQOOP_HOME} import \
--connect jdbc:mysql://192.168.10.150:3306/scrm \
--username root \
--password 123456 \
--query 'select *, '${DATESTR}' as start_time from customer where $CONDITIONS' \
--hcatalog-database itcast_dimen \
--hcatalog-table customer \
-m 10 \
--split-by id

# 1.2 导入数据到employee员工表中
${SQOOP_HOME} import \
--connect jdbc:mysql://192.168.10.150:3306/scrm \
--username root \
--password 123456 \
--query 'select *, '${DATESTR}' as start_time from employee where $CONDITIONS' \
--hcatalog-database itcast_dimen \
--hcatalog-table employee \
-m 10 \
--split-by id

# 1.3 导入数据到scrm_department部门表中
${SQOOP_HOME} import \
--connect jdbc:mysql://192.168.10.150:3306/scrm \
--username root \
--password 123456 \
--query 'select *, '${DATESTR}' as start_time from scrm_department where $CONDITIONS' \
--hcatalog-database itcast_dimen \
--hcatalog-table scrm_department \
-m 10 \
--split-by id

# 1.4 导入数据到itcast_school学校表中
${SQOOP_HOME} import \
--connect jdbc:mysql://192.168.10.150:3306/scrm \
--username root \
--password 123456 \
--query 'select *, '${DATESTR}' as start_time from itcast_school where $CONDITIONS' \
--hcatalog-database itcast_dimen \
--hcatalog-table itcast_school \
-m 10 \
--split-by id

# 1.5 导入数据到itcast_subject学科表中
${SQOOP_HOME} import \
--connect jdbc:mysql://192.168.10.150:3306/scrm \
--username root \
--password 123456 \
--query 'select *, '${DATESTR}' as start_time from itcast_subject where $CONDITIONS' \
--hcatalog-database itcast_dimen \
--hcatalog-table itcast_subject \
-m 10 \
--split-by id
